package com.panshi.comtroller;

import com.github.pagehelper.PageHelper;
import com.panshi.service.ICommentService;
import com.panshi.vo.CommentVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
@CrossOrigin
@RequestMapping("zxComment")
public class ComentController {

    @Resource
    private ICommentService iCommentService;

    @GetMapping("/queryComment/{zxId}")
    public Map<String,Object> queryCommentByZxId(@PathVariable String zxId){

        return iCommentService.queryCommentByZxId(zxId);
    }

    @GetMapping("/queryReplyByCommentId")
    public Map<String,Object> queryReplyByCommentId(String commentId,String pageNumber,String pageSize){
        PageHelper.startPage(Integer.valueOf(pageNumber),Integer.valueOf(pageSize));

        log.info("commentId:{}",commentId);
        log.info("pageNum:{}",pageNumber);
        log.info("pageSize:{}",pageSize);

        return iCommentService.queryReplyByCommentId(commentId);
    }

    @PostMapping("/addComment")
    public Map<String,Object> addComment(@RequestBody CommentVO commentVO){

        log.info("增加评论:{}",commentVO.toString());

        return iCommentService.addComment(commentVO);
    }

}
